/*
 * @Author: your name
 * @Date: 2021-04-07 15:36:33
 * @LastEditTime: 2025-03-21 08:04:04
 * @LastEditors: Lcx l1556461835@163.com
 * @Description: In User Settings Edit
 * @FilePath: \simulation-fontend\store\index.js
 */
export const strict = false;
export const state = () => ({
  gradeAll: [],
  gradeAllCal: [],
  gradeAllCalOb: [],
  gradeAllPltcm: [],
  gradeAllPltcmOb: [],
  pathName: {
    DS: "铁水脱硫",
    BOF: "转炉冶炼",
    AR: "吹氩精炼",
    RH: "RH精炼",
    LF: "LF精炼",
    CC: "连铸浇注",
    FCE: "加热炉",
    HSM: "热连轧",
    HSM2: "热连轧(中间坯)",
    LCS: "层流冷却",
    DC: "卷取",
    ZRZ: "直热装",
    LJ: "冷检",
    BP: "扒皮",
    FRZ: "视实际情况而定（优先热装）",
    JZ: "精整",
    HL: "缓冷",
    BPJY: "板坯检验",
    ZL: "装炉方式",
    JC: "检查",
    BSDK: "标识、打捆",
    RK: "入库"
  },
  pathImg: {
    DS: require("@/assets/images/tuoliu.png"),
    BOF: require("@/assets/images/zhuanlu.png"),
    AR: require("@/assets/images/chuiya.png"),
    RH: require("@/assets/images/RHjl.png"),
    LF: require("@/assets/images/lfjinglian.png"),
    CC: require("@/assets/images/lz.png"),
    FCE: require("@/assets/images/jrl.png"),
    HSM: require("@/assets/images/rm.png"),
    HSM2: require("@/assets/images/rm.png"),
    LCS: require("@/assets/images/lq.png"),
    DC: require("@/assets/images/gj.png"),
    ZRZ: require("@/assets/images/ZRZ.png"), // 直热装
    LJ: require("@/assets/images/LZZ.png"), // 冷检
    BP: require("@/assets/images/BP.png"), // 扒皮
    FRZ: require("@/assets/images/ZRZ.png"), // 视实际情况而定（优先热装）
    JZ: require("@/assets/images/JZ.png"), // 精整
    HL: require("@/assets/images/HL.png"), // 缓冷
    BPJY: require("@/assets/images/ZRZ.png"), // 板坯检验
    ZL: require("@/assets/images/LZZ.png"), // 装炉方式
    JC: require("@/assets/images/JC.png"),
    BSDK: require("@/assets/images/BSDK.png"),
    RK: require("@/assets/images/RK.png")
  },
  compareData: {
    oldData: "",
    newData: ""
  },
  isGetNew: 1,
  forQuickInput: {
    DS: null,
    BOF: null,
    AR: null,
    RH: null,
    LF: null,
    CC: null,
    ZL: null,
    BPJY: null
  },
  pickerOptions: {
    shortcuts: [
      {
        text: "最近一周",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          picker.$emit("pick", [start, end]);
        }
      },
      {
        text: "最近一个月",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          picker.$emit("pick", [start, end]);
        }
      },
      {
        text: "最近三个月",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
          picker.$emit("pick", [start, end]);
        }
      }
    ]
  },
  chemicalName: {
    chem_c: "C",
    chem_si: "Si",
    chem_mn: "Mn",
    chem_p: "P",
    chem_s: "S",
    chem_nb: "Nb",
    chem_v: "V",
    chem_ti: "Ti",
    chem_mo: "Mo",
    chem_cu: "Cu",
    chem_n: "N",
    chem_ni: "Ni",
    chem_cr: "Cr",
    chem_al: "Al",
    chem_ca: "Ca",
    chem_h: "H",
    chem_as: "As",
    chem_b: "B",
    chem_be: "Be",
    chem_bi: "Bi",
    chem_ce: "Ce",
    chem_co: "Co",
    chem_la: "La",
    chem_mg: "Mg",
    chem_o: "O",
    chem_pb: "Pb",
    chem_pd: "Pd",
    chem_sb: "Sb",
    chem_se: "Se",
    chem_sn: "Sn",
    chem_ta: "Ta",
    chem_te: "Te",
    chem_w: "W",
    chem_zn: "Zn",
    chem_zr: "Zr"
  },
  menuData: [],
  user: {},
  tokenId: "",
  tagNavList: [],
  tagNavModel: "",
  baseUrl: "",
  loginLogoPath: "",
  publicKey: "",
  apiGate: "",
  companyName: "",
  bigLogoPath: "",
  smallLogoPath: "",
  allMenus: "",
  localeInfo: [
    {
      type: "zh",
      name: "中文"
    },
    {
      type: "en",
      name: "English"
    }
  ],
  locales: ["zh", "en"],
  locale: "zh",
  fullScreen: false, // 全屏显示
  errorInfo: [] // 报警信息
});

export const getters = {
  // ...
  getJurisdiction: state => routeName => {
    var resources = state.user.resources;
    if (!state.user.resources) {
      var user = JSON.parse(localStorage.getItem("user"));
      resources = user.resources;
    }
    return resources.indexOf(routeName) > -1;
  }
};
export const mutations = {
  getJurisdiction: state => routeName => {
    var resources = state.user.resources;
    if (!state.user.resources) {
      var user = JSON.parse(localStorage.getItem("user"));
      resources = user.resources;
    }
    return resources.indexOf(routeName) > -1;
  },
  allMenus(state, allMenus) {
    state.allMenus = allMenus;
  },
  setUser(state, user) {
    if (!user) return;
    state.user = user;
  },
  SET_TOKEN(state, tokenId) {
    if (!tokenId) return;
    state.tokenId = tokenId;
  },
  SET_LANG(state, locale) {
    if (state.locales.indexOf(locale) !== -1) {
      state.locale = locale;
    }
  },
  setInitInfo(state, result) {
    state.publicKey = result.publicKey;
    state.apiGate = result.apiGate;
    if (!result.version) {
      return;
    }
    var versionInfo =
      typeof result.version.content === "string"
        ? JSON.parse(result.version.content)
        : result.version.content;
    state.companyName = versionInfo[0];
    state.bigLogoPath = (versionInfo[3] ? versionInfo[3] : "").split(":")[1]; // 找张默认图片
    state.smallLogoPath = (versionInfo[2] ? versionInfo[2] : "").split(":")[1];
    state.baseUrl =
      versionInfo.length < 5 ? "http://localhost:8099" : versionInfo[4];
    state.loginLogoPath = (versionInfo[5] ? versionInfo[5] : "").split(":")[1]; // 登录页logo
  },
  SET_ERROR_INFO(state, errorInfo) {
    if (state.errorInfo.length >= 50) {
      state.errorInfo.pop();
    }
    state.errorInfo.unshift(errorInfo);
  }
};

export const actions = {
  // async nuxtServerInit({ commit }, { app }) {
  //   const result = await app.$axios.$post("/user/getPublicKey.form", {
  //     version: 0
  //   });
  //   commit("setInitInfo", result);
  // },
  saveUser({ commit }, user) {
    commit("setUser", user);
    if (process.client) {
      localStorage.setItem("tokenId", user.token);
      localStorage.setItem("roleID", user.role);
      commit("SET_TOKEN", user.token);
    }
  },
  getTokenId({ commit }) {
    if (process.client) {
      const token = localStorage.getItem("tokenId");
      if (token) {
        commit("SET_TOKEN", token);
      }
    }
  }
};
